Skip to content

fix: code config values and UI settings save both ignored defaults#676

Open
FarbodGhasemi wants to merge 1 commit into
VirtusLab-Open-Source:masterfrom
FarbodGhasemi:fix/config-priority-and-allowedlevels-ui-save
Open

fix: code config values and UI settings save both ignored defaults#676
FarbodGhasemi wants to merge 1 commit into
VirtusLab-Open-Source:masterfrom
FarbodGhasemi:fix/config-priority-and-allowedlevels-ui-save

Conversation

@FarbodGhasemi

Copy link
Copy Markdown

Ticket

N/A

Summary

Fixes two independent bugs where plugin configuration values were silently ignored.

Bug 1 — Server: plugins.ts code config values overridden by hard-coded defaults

In server/src/config/setup.ts, configSetup merged configBase.default into configRaw before
building the fallback chain. This meant the hard-coded default always appeared as a DB value and
won, so any key set in plugins.ts (e.g. allowedLevels: 5) was silently discarded.

Fix: separate the raw DB read (dbConfig) from the Zod validation object and apply the correct
priority order: DB value → code config (plugins.ts) → hard-coded default.

Bug 2 — UI: changing allowedLevels in admin settings reverts to default on save

NumberInput from @strapi/design-system delivers its parsed value via onValueChange, not
onChange. The existing onChange handler received a non-string first argument, so
isString(fieldName) returned false and setFormValueItem was never called.
formValue.allowedLevels stayed at the server's initial value while the input display (driven by
the Form component's internal state) correctly showed the user's edit — causing the stale value to
be submitted on save.

Fix: switch NumberInput to onValueChange and pass the field name explicitly to handleChange.

Additional:

  • useInitialConfig: useRef guard so the form is seeded from server data only once per mount,
    preventing background refetches from overwriting in-progress edits
  • useSaveConfig: invalidate the config query after a successful save
  • SettingsPage: move queryClient.invalidateQueries() into useEffect (was running on every
    render)
  • Test infrastructure: outDir in server/tsconfig.json + tsconfig path in jest.config.ts
    for ts-jest
  • Regression test: configSetup with empty DB respects a code config allowedLevels value

Test Plan

  • Set allowedLevels: 5 in config/plugins.ts with no prior DB config → server bootstraps with
    5, not 2
  • Navigate to Settings, change allowedLevels to 4, click Save → PUT body contains 4; value
    persists after restart
  • yarn jest → 175 passing, 2 todo, 1 pre-existing failure (CommonService › getSlug() — ESM/CJS
    issue with @sindresorhus/slugify, unrelated to this PR)

Two bugs fixed:

1. Server (setup.ts): `plugins.ts` code config values were silently
   ignored for any key that already had a hard-coded default. The
   original code merged `configBase.default` into `configRaw` before
   building the priority chain, so the hard-coded default always won.
   Fixed by separating the raw DB read (`dbConfig`) from the Zod
   validation object, then applying the correct priority order:
   DB value → code config (plugins.ts) → hard-coded default.

2. UI (AdditionalSettingsPanel): `NumberInput` from @strapi/design-system
   exposes the parsed number via `onValueChange`, not `onChange`. The
   previous `onChange` handler received a raw value that was not a
   string field name, so `isString(fieldName)` evaluated to false and
   `setFormValueItem` was never called. `formValue.allowedLevels` stayed
   at 2 while the input display (driven by the Form component's internal
   `values`) correctly showed the user's input — causing the stale value
   to be submitted on save. Fixed by switching to `onValueChange`.

Also included:
- useInitialConfig: guard with useRef so the form is only seeded from
  the server once per mount, preventing background refetches from
  overwriting user edits
- useSaveConfig: invalidate the config query after a successful save
- SettingsPage: move queryClient.invalidateQueries() into useEffect so
  it runs once on mount instead of on every render
- Test infrastructure: add outDir to server/tsconfig.json and tsconfig
  path to jest.config.ts so ts-jest resolves correctly
- Regression test: configSetup respects code config allowedLevels when
  DB is empty
@FarbodGhasemi FarbodGhasemi force-pushed the fix/config-priority-and-allowedlevels-ui-save branch from 7bd8cbd to 649e632 Compare June 7, 2026 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant